<?php

namespace app\api\controller;

use Firebase\JWT\JWT;

class Home extends Base
{   
    public function initialize()
    {
        //验证token鉴权
        parent::initialize();
        $header = request()->header();
        $jwt=new JWT();
        $key = 'api'; 
        $payload = [
        // 'iss' => "http://www.api.io",
        // 'aud' => "http://www.api.io",
        'iat' => time(),
        'nbf' => time(),
        'exp'=>time()+60*60*24,
        'uid'=>4,
        ];
  
        $token=$jwt::encode($payload,$key);

        if (!isset($token)) {
            return json(['code'=>0,'msg'=>'token不能为空'],400)->send();
        }   

        $key='api';
        try {
           $info= JWT::decode($token,$key,array('HS256'));
        } catch (\Exception $e) {
            return json(['code'=>0,'msg'=>$e->getMessage()],400)->send();
        }
       $this->uid= $info->uid;   
        
    }
}
